home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************/
- /* Header declarations of lex function and related stuff */
- /* + Keywords consist of letters,digits and _ , first char must be */
- /* a letter */
- /* + Permits forcing of expected types */
- /* + Eliminates c style comments */
- /*********************************************************************/
-
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
- /* include the yacc header file (use yacc -d) */
- /* for definition of tokens */
- /* #include "y.tab.h" */
- /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
-
-
- /*********************************************************************/
- /**** Lex-functions **************************************************/
- /*********************************************************************/
- /* Lex-struct consists of object type and object value */
- /* object type: int */
- /* object value will be stored as a struct: */
- /* either real or int number (union: wert.n.r, wert.n.i) */
- /* or pointer to char-field (wert.c) of length LEX_MAXWERT */
- /* file end is: type "EOLX" (-1) */
-
- #define LEX_MAXWERT 256
-
- typedef struct {
- int typ;
- struct {
- char *c;
- union {
- int i;
- double r;
- } n;
- } wert;
- } LEX;
-
-
- /* Lex-function: parameter: fep: pointer to readable file */
- /* force: force expected type */
- /* if fep==NULL then it will ask t_setfep */
- /* use "t_lex(fep,NO_FORCE)" for unforced lex */
- /* returns: pointer to t_lexx or NULL, */
- /* if syntax error */
- LEX *t_lex(FILE *fep,int force);
-
-
- /* function for setting filepointer and flags */
- /* returns current filepointer, if fep==NULL; */
- /* else sets and returns current filepointer */
- /* Flags: Bit 0: return EOLN, for line-sensitive syntax */
- /* Bit 1: case-insensitive */
- FILE *t_setfep(FILE *fep, long flags);
-
-
- /* returns string for error message */
- /* this string has got ca. 80 chars reserved for your own purpose */
- char *t_pos(void);
-
- /*********************************************************************/
- /**** Symbol table ***************************************************/
- /*********************************************************************/
- typedef struct t_node {
- char *s; /* name */
- int n; /* number */
- struct t_node *l; /* left branch */
- struct t_node *r; /* right branch */
- struct t_node *nl; /* next element */
- struct t_node *a; /* alias */
- void *p; /* for users purp. */
- int c; /* user code */
- } T_NODE;
-
- /* simple symbol table manager, one symbol table only */
- /* input: string, returns: T_NODE-ptr, NULL on error */
- /* table contains any KW */
- T_NODE *t_symtable(char *str);
-
- /* finds symbol n, returns T_NODE (NULL if error) */
- T_NODE *t_symfind(int n);
-
- /* performs action on all items with code */
- /* if code <0, performs action on all items */
- /* action will get T_NODE */
- /* returns: sum of action's returns */
- int t_symwalk(int code, int (*action)(T_NODE *));
-
- /* performs action on tnodes and deletes any tnode and any tnode->p */
- /* returns number of deleted nodes */
- int t_symdel(void (*action)(T_NODE *));
-
- /*********************************************************************/
- /**** Associations ***************************************************/
- /*********************************************************************/
-
- /* Association list: type(num) <-> type(name) */
- /* Try to avoid confusion with tokens defined by yacc. */
- #ifndef EOLX
- #define EOLX (EOF) /* end of text */
- #endif
- #ifndef EOLN
- #define EOLN (-2) /* end of line */
- #endif
- #ifndef ZAHL
- #define ZAHL (-3) /* "number" */
- #endif
- #ifndef REAL
- #define REAL (-4) /* "real number" */
- #endif
- #ifndef BEZEICHNER
- #define BEZEICHNER (-5) /* "varname" */
- #endif
-
- /* internal associations, don't redefine */
-
- #define KW (-6) /* keyword = string */
- /* of letters,digit,_, 1.=letter, last may be any except space */
- #define LEX_UNDEF (-7) /* undef char */
- #define LEX_SPACE (-8) /* elim space only */
- #define LEX_COM (-9) /* eliminates c-like */
- /* comments */
- #define NO_FORCE (-10) /* f:no force */
- #define LEX_PUSH (-11) /* f:push last expr. */
- #define LEX_RCHAR (-12) /* f:rec single char */
-
- /* returns number for tokentyp n */
- int t_tokenval(int n);
- /* returns string for tokentyp n */
- char *t_tokenstr(int n);
- /* returns tokentyp for number n */
- int t_valtoken(int n);
- /* returns string for number n */
- char *t_valstr(int n);
-
- /* The Token used. TOKENSET contains the words, TOKENTYP the */
- /* associated numbers. TOKENSET ends with "", TOKENTYP ends with */
- /* the value associated to unrecognized words (eg. variable names) */
- /* Use field initialization syntax. */
-
- #define END 257
- #define REM 258
- #define B_VAL 259 /* single value */
- #define B_VEC 260 /* vector */
- #define B_OBJ 261 /* visual object */
- #define GOTO 262
- #define ABS 263
- #define BEZ_VEC 264
- #define BEZ_OBJ 265
- #define TRACE 266
- #define LET 267
- #define PRINT 268
- #define LIST 269
- #define B_STR 270
- #define SCALE 271
- #define ROTATE 272
- #define TRANSLATE 273
- #define PI 274
- #define LOAD 275
- #define SAVE 276
- #define IF 277
- #define THEN 278
- #define STOP 279
- #define CONT 280
- #define GOSUB 281
- #define RETURN 282
- #define DELETE 283
- #define B_FLD 284 /* data field */
- #define B_NUM 285 /* number */
- #define DIM 286
- #define FOR 287
- #define TO 288
- #define STEP 289
- #define NEXT 290
- #define B_FOR 291 /* FOR-TO-LOOP */
- #define NEW 292
- #define RUN 293
- #define SIN 294
- #define COS 295
- #define TAN 296
- #define B_FKT 297 /* function */
- #define ASIN 298
- #define ACOS 299
- #define ATAN 300
- #define VX 301
- #define VY 302
- #define VZ 303
- #define EXP 304
- #define POW 305
- #define LOG 306
- #define SQRT 307
- #define ROT 308
- #define SCA 309
- #define RND 310
- #define FOPEN 311
- #define FPRINT 312
- #define V0 313
- #define CTDS 314
- #define PLANE 315
- #define BIT 316
- #define UNION 317
- #define SECT 318
- #define DIFF 319
- #define ADDOBJ 320
- #define TEX 321
- #define BOUND 322
- #define TRANSFORM 323
- #define SQR 324
- #define PER 325
-
- #define TOKENSET {\
- "END",\
- "REM",\
- "GOTO",\
- " ",\
- " ",\
- " ",\
- " ",\
- " ",\
- " ",\
- " ",\
- " ",\
- "ABS",\
- "^",\
- "$",\
- "TRACE",\
- "LET",\
- "PRINT",\
- "LIST",\
- "SCALE",\
- "ROTATE",\
- "TRANSLATE",\
- "PI",\
- "V0",\
- "LOAD",\
- "SAVE",\
- "IF",\
- "THEN",\
- "STOP",\
- "CONT",\
- "GOSUB",\
- "RETURN",\
- "DELETE",\
- "DIM",\
- "FOR",\
- "TO",\
- "STEP",\
- "NEXT",\
- "NEW",\
- "RUN",\
- "SIN",\
- "COS",\
- "TAN",\
- "ASIN",\
- "ACOS",\
- "ATAN",\
- "VX",\
- "VY",\
- "VZ",\
- "EXP",\
- "POW",\
- "LOG",\
- "SQRT",\
- "ROT",\
- "SCA",\
- "RND",\
- "FOPEN",\
- "FPRINT",\
- "CTDS",\
- "PLANE",\
- "BIT",\
- "UNION",\
- "DIFF",\
- "SECT",\
- "ADDOBJ",\
- "TEX",\
- "BOUND",\
- "TRANSFORM",\
- "SQR",\
- "PER",\
- ""}
-
- #define TOKENTYP {\
- END,\
- REM,\
- GOTO,\
- B_VAL,\
- B_VEC,\
- B_OBJ,\
- B_STR,\
- B_FLD,\
- B_NUM,\
- B_FOR,\
- B_FKT,\
- ABS,\
- BEZ_VEC,\
- BEZ_OBJ,\
- TRACE,\
- LET,\
- PRINT,\
- LIST,\
- SCALE,\
- ROTATE,\
- TRANSLATE,\
- PI,\
- V0,\
- LOAD,\
- SAVE,\
- IF,\
- THEN,\
- STOP,\
- CONT,\
- GOSUB,\
- RETURN,\
- DELETE,\
- DIM,\
- FOR,\
- TO,\
- STEP,\
- NEXT,\
- NEW,\
- RUN,\
- SIN,\
- COS,\
- TAN,\
- ASIN,\
- ACOS,\
- ATAN,\
- VX,\
- VY,\
- VZ,\
- EXP,\
- POW,\
- LOG,\
- SQRT,\
- ROT,\
- SCA,\
- RND,\
- FOPEN,\
- FPRINT,\
- CTDS,\
- PLANE,\
- BIT,\
- UNION,\
- DIFF,\
- SECT,\
- ADDOBJ,\
- TEX,\
- BOUND,\
- TRANSFORM,\
- SQR,\
- PER,\
- BEZEICHNER}
-
-
- /* value of single chars (from CHRSET) will be the char itself */
- #ifndef CHRSET
- #define CHRSET "+-*/<>=&|!,[]()#\"[]@%"
- #endif
-
-
-